# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4

##
## Copyright (C) 2009 - George Y. Kussumoto <georgeyk.dev@gmail.com>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., or visit: http://www.gnu.org/.
##
##
""" Battle Page Definition """

import google.appengine.ext.db as db

from twitheroapp.base import BaseTemplatePage
from twitheroapp.models.battle import Battle
from twitheroapp.models.hero import Hero


class BattlePage(BaseTemplatePage):
    template_file = 'battle.html'
    page_values = {}

    def get(self, battle_key):
        self._battle_key = battle_key
        try:
            battle = Battle.get(battle_key)
        except:
            self.redirect('/')
            return

        self.page_values['battle'] = battle
        self.page_values['show_results'] = False
        self.template_render()

    def post(self, *args):
        self.page_values['show_results'] = True
        battle = self.page_values['battle']
        battle.do_fight()
        battle.put()
        self.page_values['battle'] = battle
        self.template_render()
